package crmdna.common;

import java.util.regex.Pattern;

public class Utils {
  public static String removeSpaceUnderscoreBracketAndHyphen(String s) {
    if (s == null)
      return null;

    s = s.replaceAll(Pattern.quote("_"), "");
    s = s.replaceAll(Pattern.quote(" "), "");
    s = s.replaceAll(Pattern.quote("-"), "");
    s = s.replaceAll(Pattern.quote("("), "");
    s = s.replaceAll(Pattern.quote(")"), "");

    return s;
  }

  public static boolean isValidEmailAddress(String email) {
    if (null == email)
      return false;

    boolean stricterFilter = true;
    String stricterFilterString = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    String laxString = ".+@.+\\.[A-Za-z]{2}[A-Za-z]*";
    String emailRegex = stricterFilter ? stricterFilterString : laxString;
    java.util.regex.Pattern p = java.util.regex.Pattern.compile(emailRegex);
    java.util.regex.Matcher m = p.matcher(email);
    return m.matches();
  }
}
